From: Ævar Arnfjörð Bjarmason Date: Thu, 7 Apr 2005 19:05:42 +0000 (+0000) Subject: * A new function, "dateFormat" that allows code duplication in the children. X-Git-Tag: 1.5.0alpha1~356 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=d7f0ff2e8b3476175aee89cbc621fc03fba70c60;p=lhc%2Fweb%2Fwiklou.git * A new function, "dateFormat" that allows code duplication in the children. * Documented * Rewrote date(), time() and timeanddate() to take atvantage of this new function and removed $ts=wfTimestamp(TS_MW,$ts); from all of them, they should only ever be passed time in the format of TS_MW. --- diff --git a/languages/Language.php b/languages/Language.php index 952d02bbbb..df25286005 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -1,5 +1,7 @@ + * function timeanddate([...], $format = '0') { + * $datePreference = $this->dateFormat($format); + * [...] + * + * + * @param mixed $format + * @return string + */ + function dateFormat( $format ) { + global $wgUser; + + if ( MW_DATE_USER_FORMAT === true) { + // Some files, such as Parser.php want us to return the + // default format no matter what, obey them! + if ($format === false) { + return false; // Pass it along.. + } elseif ( $wgUser->isLoggedIn() ) { + return $wgUser->getOption( 'date' ); + } else { + return '0'; + } + } else { + $options = $this->getDefaultUserOptions(); + return $options['date']; + } + } + /** * @access public * @param mixed $ts the time format which needs to be turned into a @@ -2067,24 +2105,14 @@ class Language { * validateTimeZone() in Special:Preferences * @return string */ - function date( $ts, $adj = false, $format = MW_DATE_USER_FORMAT, $timecorrection = false ) { + function date( $ts, $adj = false, $format = '0', $timecorrection = false ) { global $wgAmericanDates, $wgUser; - $ts=wfTimestamp(TS_MW,$ts); // FIXME: Is this even needed anymore? - if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); } - // It's probably best to turn this whole mess into a function -ævar - if ( $format ) { - $datePreference = $wgUser->getOption( 'date' ); - } else { - $options = $this->getDefaultUserOptions(); - $datePreference = $options['date']; - } - - if ($datePreference == '0') { // Not == 0 for the obvious reasons - $datePreference = $wgAmericanDates ? 1 : 2; - } + $datePreference = $this->dateFormat($format); + + if ($datePreference == '0') {$datePreference = $wgAmericanDates ? '0' : '2';} $month = $this->getMonthName( substr( $ts, 4, 2 ) ); $day = $this->formatNum( 0 + substr( $ts, 6, 2 ) ); @@ -2110,22 +2138,17 @@ class Language { * validateTimeZone() in Special:Preferences * @return string */ - function time( $ts, $adj = false, $format = MW_DATE_USER_FORMAT, $timecorrection = false ) { + function time( $ts, $adj = false, $format = '0', $timecorrection = false ) { global $wgUser, $wgAmericanDates; - $ts=wfTimestamp(TS_MW,$ts); if ( $adj ) { $ts = $this->userAdjust( $ts, $timecorrection ); } - - if ( $format ) { - $datePreference = $wgUser->getOption( 'date' ); - } else { - $options = $this->getDefaultUserOptions(); - $datePreference = $options['date']; - } if ($datePreference == '0') {$datePreference = $wgAmericanDates ? 1 : 2;} + $datePreference = $this->dateFormat($format); + + if ($datePreference == '0') {$datePreference = $wgAmericanDates ? '0' : '2';} $t = substr( $ts, 8, 2 ) . ':' . substr( $ts, 10, 2 ); - if ( $format == 'ISO 8601' ) { + if ( $datePreference === 'ISO 8601' ) { $t .= ':' . substr( $ts, 12, 2 ); } return $this->formatNum( $t ); @@ -2141,25 +2164,18 @@ class Language { * default one. * @param string $timecorrection the time offset as returned by * validateTimeZone() in Special:Preferences - * @param ??? $dateandtime ??? (default false) * @return string */ - function timeanddate( $ts, $adj = false, $format = MW_DATE_USER_FORMAT, $timecorrection = false, $dateandtime = false) { + function timeanddate( $ts, $adj = false, $format = '0', $timecorrection = false) { global $wgUser, $wgAmericanDates; - $ts=wfTimestamp(TS_MW,$ts); - - if ( $format ) { - $datePreference = $wgUser->getOption( 'date' ); - } else { - $options = $this->getDefaultUserOptions(); - $datePreference = $options['date']; - } if ($datePreference == '0') {$datePreference = $wgAmericanDates ? 1 : 2;} + + $datePreference = $this->dateFormat($format); switch ( $datePreference ) { - case 'ISO 8601': return $this->date( $ts, $adj, $format, $timecorrection ) . ' ' . - $this->time( $ts, $adj, $format, $timecorrection ); - default: return $this->time( $ts, $adj, $format, $timecorrection ) . ', ' . - $this->date( $ts, $adj, $format, $timecorrection ); + case 'ISO 8601': return $this->date( $ts, $adj, $datePreference, $timecorrection ) . ' ' . + $this->time( $ts, $adj, $datePreference, $timecorrection ); + default: return $this->time( $ts, $adj, $datePreference, $timecorrection ) . ', ' . + $this->date( $ts, $adj, $datePreference, $timecorrection ); } }